// Player.cpp

// Implementacia objektu sveta reprezentujuceho hraca

#include "Player/World/Player.h"

// Konstruktor - pociatocne inicializovanie na null/false hodnoty
Player::Player(World* w) : Movable(w)
{
	side = UNKNOWN;
	uniform = 0;
	goalie = false;

	absDir = RadAngle(0);
	neckDir = RadAngle(0);
	dirValid = false;
	armValid = false;

	if(world->params->types == NULL)
		type = NULL;
	else
		type = world->params->types[0];
}

// Kopirovaci konstruktor
Player::Player(const Player& player) : Movable(player)
{
	side	= player.side;
	uniform = player.uniform;
	goalie	= player.goalie;

	absDir		= player.absDir;
	neckDir		= player.neckDir;
	dirValid	= player.dirValid;
	armDir		= player.armDir;
	armValid	= player.armValid;

	type = player.type;
}

// Destruktor
Player::~Player()
{

}

// Operator priradenia
Player& Player::operator =(const Player& player)
{
	// Neprepisuj sameho seba
	if(&player == this)
		return *this;

	// Je toto potrebne?
	Movable::operator =(player);

	side	= player.side;
	uniform = player.uniform;
	goalie	= player.goalie;

	absDir		= player.absDir;
	neckDir		= player.neckDir;
	dirValid	= player.dirValid;
	armDir		= player.armDir;
	armValid	= player.armValid;

	type = player.type;

	return *this;
}

// Nastavi typ hraca
void Player::SetType(int i)
{
	if(world->params->types == NULL)
		return;

	if(uniform == 0 || side != OUR)
	{
		type = world->params->types[0];
	}
	else
	{
		world->friendTypes[uniform] = world->params->types[i];
		type = world->params->types[i];
	}
}

// Nastavi cislo dresu hraca
void Player::SetUniform(int u)
{
	uniform = u;

	if(world->params->types == NULL)
		return;

	if(side != OUR)
		type = world->params->types[0];
	else 
		type = world->friendTypes[uniform];
}

// Nastavi stranu hraca, na ktorej bude hrat
void Player::SetSide(Side s)
{
	side = s;

	if(world->params->types == NULL)
		return;

	if(side != OUR)
		type = world->params->types[0];
	else
		type = world->friendTypes[uniform];
}

// Predpoveda stav hraca v dalsom kroku
void Player::Step()
{
	pos += vel;
	vel *= type->player_decay;
	age++;
}
